<?php
use app\assets\CommissionAsset;
use yii\helpers\Html;

CommissionAsset::register($this);
?>

<div id="toolbar" style="margin-bottom: -35px">
    <div>
    <select class="form-control" style="width: 120px" id="yearSelect">
    </select>
    <select class="form-control " style="width: 120px; margin-left: 130px; margin-top: -34px;" id="monSelect">
        <option value="01">一月</option>
        <option value="02">二月</option>
        <option value="03">三月</option>
        <option value="04">四月</option>
        <option value="05">五月</option>
        <option value="06">六月</option>
        <option value="07">七月</option>
        <option value="08">八月</option>
        <option value="09">九月</option>
        <option value="10">十月</option>
        <option value="11">十一月</option>
        <option value="12">十二月</option>
    </select>
        <button id="siftBtn" class="btn btn-primary" style="margin-left: 280px; margin-top: -70px;">
            确定筛选
        </button>

        <button id="allBtn" class="btn btn-primary" style="margin-left: 30px; margin-top: -70px;">
            查看全部
        </button>

    </div>
</div>

<table id="table">
</table>

<script>

    //对选择器的设置
    var myDate = new Date();
    var mon = myDate.getMonth()+1;
    var year = myDate.getFullYear();
    if (mon<10){
        mon='0'+mon;
    }
    $("#monSelect").val(mon);
    var lastYear=year-1;
    var theYearBeforeLast=year-2;
    $("#yearSelect").append('<option selected value='+year+'>'+year+'年</option>');
    $("#yearSelect").append('<option value='+lastYear+'>'+lastYear+'年</option>');
    $("#yearSelect").append('<option value='+theYearBeforeLast+'>'+theYearBeforeLast+'年</option>');



    //选择具体某个月
    $(function() {

        $('#siftBtn').click(function(){
            $year= $("#yearSelect option:selected").val();
            $mon= $("#monSelect option:selected").val();

            $url="getallgradedata?year="+$year+"&mon="+$mon;
            console.log($url);
            $('#table').bootstrapTable('removeAll');//先清空缓存
            $('#table').bootstrapTable('refreshOptions',{url:$url});
        });

        $('#allBtn').click(function(){

            $("#monSelect").val("");
            $("#yearSelect").val("");
            $url="getallgradedata";
            console.log($url);
            $('#table').bootstrapTable('removeAll');//先清空缓存
            $('#table').bootstrapTable('refreshOptions',{url:$url});
        });

    });


    //初始化表格设置
    $('#table').bootstrapTable({
        height: 800,//高度
        toolbar: '#toolbar',        //工具按钮用哪个容器
        clickToSelect: true,//点击行即可选中单选/复选框
        singleSelect: false,//复选框只能选择一条记录
        search: false,//是否显示右上角的搜索框
        striped: true,      //是否显示行间隔色
        cache: false,            //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        sidePagination: "server", //服务端处理分页
        pagination: true,     //是否显示分页（*）
        sortable: false,           //是否启用排序
        sortOrder: "asc",          //排序方式
        method: 'get',      //请求方式（*）
        pageNumber:1,      //初始化加载第一页，默认第一页
        pageSize: 20,      //每页的记录行数（*）
        pageList: [10, 20, 50, 100],  //可供选择的每页的行数（*）
        cardView: false,          //是否显示详细视图
        uniqueId:'brokerage_id',
        url:"getallgradedata",

        columns: [{
            field: 'orderform_money_total',
            align: 'center',
            valign: 'middle',
            title: '订单总额'
        },{
            field: 'brokerage_money_total',
            align: 'center',
            valign: 'middle',
            title: '佣金总额',
            formatter:function(value,row,index){
                var a = '<span style="color: #f60;margin: 0 0 0px;height: 200px">'+'¥ '+row.brokerage_money_total+'</span>'
                return a;
            }
        },{
            field: 'user_name',
            align: 'center',
            valign: 'middle',
            title: '受益人'
        },{
            field: 'createTime',
            align: 'center',
            valign: 'middle',
            title: '结算月份'
        },{
            field: 'is_transfer',
            align: 'center',
            valign: 'middle',
            title: '状态',
            formatter:function(value,row,index){
                if(row.is_transfer==0){
                    var a = '<button class="btn btn-primary" onclick="transferClick(\''+ row.user_id + '\',\'' +row.createTime+ '\')">去打款</button>';
                    var time =row.createTime;
                    var myDate = new Date();
                    var mon = myDate.getMonth()+1;
                    if (mon<10){
                        mon='0'+mon;
                    }
                    var year = myDate.getFullYear();
                    var yearmon =  year+'-'+mon;
                    if(time==yearmon){
                        return '<button class="btn btn-default" disabled="disabled" >当前月无法结算 </button>';
                    }else{
                        return a;
                    }
                }else if(row.is_transfer==1){
                    var a = '<span style="color: #f60;margin: 0 0 0px;height: 200px">已结算</span>';
                    return a;
                }
            }
        }]
    });


    $('input').attr('placeholder','搜索订单号');

    $(window).resize(function () {
        $('#table').bootstrapTable('resetView');

    });

    function transferClick(user_id,createTime){
        $.ajax({
            type:"GET",
            dataType:"json",
            data:{"user_id":user_id,"createTime":createTime},
            url:"transfer-operate",
            success:function() {
                $('#table').bootstrapTable('refresh');
                alert("已确定完成打款操作");
            }
        });
    }

</script>